package com.netty.cn.rpc.string.server;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * 
 * @author wangzonghui
 * @date 2021-07-19 16:34:00
 * @Description 第二个serverhandler
 */
public class StringServerHandler2  extends ChannelInboundHandlerAdapter {
    
	/**
	 * 数据接收处理
	 */
	@Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("ServerHandler2 接收到信息:"+msg.toString());
        ctx.channel().writeAndFlush("ServerHandler2 返回消息 !"+System.currentTimeMillis());
    }
    
    /**
     * 关闭回调
     */
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
    	super.exceptionCaught(ctx,cause);
        System.out.println(ctx.channel().remoteAddress()+" 关闭连接");
    }
}
